package pers.kw.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import pers.kw.config.ConfirmConfig;
import pers.kw.config.FirstQueueConfig;

import java.nio.charset.StandardCharsets;

@Slf4j
@Component
public class RabbitMQListener {

    //@RabbitListener(queues = ConfirmConfig.CONFIRM_QUEUE_NAME)
    public void receive(Message message) {
        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
        log.info("接收到的消息是：{}", msg);
    }

    //@RabbitListener(queues = ConfirmConfig.BACKUP_QUEUE_NAME)
    public void receiveBackup(Message message) {
        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
        log.info("备份队列接收到的消息是：{}", msg);
    }

    /**
     * 优先级队列
     *
     * @param message
     */
    @RabbitListener(queues = FirstQueueConfig.QUEUE_NAME)
    public void receiveFirstQueue(Message message) {
        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
        System.out.println("消费：" + msg);
    }
}
